package com.servlet;

import com.dao.StudenCla;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/uptest2")
public class ModifyClass extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        updataClass(req,resp);
    }

    //修改
    private void updataClass(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = Integer.valueOf(req.getParameter("id"));
        String name = req.getParameter("name");
        if (id != null) {
            StudenCla studenCla = new StudenCla();
            try {
                studenCla.studenCla(id,name);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            //            resp.sendRedirect("list.jsp");
            CheckClass.checkCl(req, resp);
            resp.sendRedirect("checktest");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
